package com.glodon.cloud.controller;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import com.glodon.cloud.domain.User;

@RestController
public class UserController {
	
	@Autowired
	private JdbcTemplate  jdbcTemplate ; 
	
	@GetMapping("/user/list")
	public Object listUsers(){
		String sql = "select * from sys_user "  ; 
		List<User> userList =  this.jdbcTemplate.query(sql,BeanPropertyRowMapper.newInstance(User.class) ); 
		return userList ; 
	}
	
	@GetMapping("user/id/{id}")
	public Object findUserById(@PathVariable("id") String userid){
		String sql = "select * from sys_user  where id = ? "  ; 
		User user =  this.jdbcTemplate.queryForObject(sql,new String[]{userid} , BeanPropertyRowMapper.newInstance(User.class));
		return user ; 
	}
}
